<?php
namespace app\index\controller;

use app\common\lib\aliyun\AliSms;
use app\common\lib\Util;
use think\Controller;
use app\common\lib\Redis;

class Index extends Controller
{
    public function index()
    {
        return '';
    }

    public function second(){
        print_r($_GET);
        echo "baibai,xuge";
    }

    public function hello($name = 'ThinkPHP5')
    {
        echo 'hello,' . $name;
    }

    public function sendSms(){
        $code = "1234";
        $mobile = "15222202530";
//        $alisms = new AliSms();
//        $result = $alisms->sign(config("app.alidayu.valid_sign"))->data(['name' => '', 'code' => "$code"])->code(config("app.alidayu.valid_template"))->send($mobile);
        $redis = new \Swoole\Coroutine\Redis();
        $redis->connect(config('redis.host'),config('redis.port'));
        $val = $redis->get('key4');
        echo $val;
        //$redis->set(Redis::smsKey($mobile),$code,Config('redis.time_out'));
    }

    public function test(){
        //异步redis
        $client = new \swoole_redis;
        $client->connect('127.0.0.1', 6379, function (\swoole_redis $client, $result) {
            if ($result === false) {
                echo "connect to redis server failed.\n";
                return;
            }
            $client->set('live_key', 'swoole', function (\swoole_redis $client, $result) {
                var_dump($result);
            });
        });
    }

    public function test2(){
        $phoneNum = "15222202530";
        $code = "1234";
        $client = new \swoole_redis;
        $client->connect(config('redis.host'), config('redis.port'), function (\swoole_redis $client, $result)  use ($phoneNum, $code){
            if ($result === false) {
                echo "connect to redis server failed.\n";
                return;
            }
            $client->set(Redis::smsKey($phoneNum),$code,function (\swoole_redis $client, $result){
                var_dump($result);

            });
        });
    }


}
